def max_heap(lst, value):
lst.append(value) # Add the new value to the end of the heap
idx = len(lst) - 1 # Get the index of the newly added element
# Moving the newly added element up the tree as long as it's greater
# than its parent, maintaining the max heap property
while idx > 0:
parent_index = (idx - 1) // 2
if lst[idx] > lst[parent_index]:
lst[idx], lst[parent_index] = lst[parent_index], lst[idx]
idx = parent_index
else:
break